<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>添加资源位</title>
</head>
<body>
<div style="width:100%">

    <div class="items clearfix">
        <h2 style="" class="tal">正在操作：添加商品资源位</h2>
        <div class="items2">

            <!--{if $error_msg}-->

            <div class="error-box">
                <!--{$error_msg}-->
            </div>

            <!--{elseif !$source_category_array}-->

            <div class="error-box">
                <!--{$error_msg}-->
            </div>

            <!--{else}-->

            <div class="select-box">
                <div class="selected" onclick="source.change(4);">商品资源位</div>
                <div onclick="source.change(5);">图片资源位</div>
            </div>

            <div>
                <form id="source_form" onsubmit="return false;">
                    <table>
                        <tbody>
                        <tr>
                            <td class="tar" width="150">资源位分类：</td>
                            <td width="500">
                                <select id="parnet_id" name="parnet_id">
                                    <!--{foreach from=$source_category_array item=source}-->
                                        <!--{if $source->parent_category_id == 0}-->
                                            <option value="<!--{$source->source_category_id}-->" disabled="disabled"><!--{$source->source_category_title}--></option>
                                        <!--{else}-->
                                            <option value="<!--{$source->source_category_id}-->">&nbsp;&nbsp;<!--{$source->source_category_title}--></option>
                                        <!--{/if}-->
                                    <!--{/foreach}-->
                                </select>
                                <font color="red">*</font>
                            </td>
                            <td width="*" rowspan="5">
                                <div id="show_img" style="border: 1px solid #CCCCCC;height: 185px;margin: 0 auto;width: 185px;"></div>
                                <input type="hidden" name="promotion_img" id="promotion_img" value="" />
                            </td>
                        </tr>
                        <tr>
                            <td class="tar">商品编码：</td>
                            <td>
                                <input type="text" name="product_code" id="product_code" style="width: 100px;" />
                                <a href="javascript: void(0);" onclick="source.clearGoods();" id="clearBtn" style="display: none;">取消</a>
                                <font color="red">*</font>
                                <font class="gray">输入商品编码后，按回车键查询商品信息</font>
                                <input type="hidden" name="hidden_product_code" id="hidden_product_code" />
                            </td>
                        </tr>
                        <tr>
                            <td class="tar">商品名称：</td>
                            <td id="goods_name"></td>
                        </tr>
                        <tr>
                            <td class="tar">当前销售价：</td>
                            <td id="goods_price" class="red"></td>
                        </tr>
                        <tr>
                            <td class="tar">使用标志：</td>
                            <td>
                                <input type="radio" value="1" name="useFlg" checked="checked" /> 启用
                                <input type="radio" value="0" name="useFlg" /> 禁用
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr>
                            <td class="tar">是否打开新页面：</td>
                            <td>
                                <input type="radio" value="1" name="openPage" checked="checked" /> 是
                                <input type="radio" value="0" name="openPage" /> 否
                                <font color="red">*</font>
                                <input type="hidden" name="id" value="0" />
                            </td>
                            <td class="tac">
                                <input type="button" value="上传图片" class="btn" onclick="source.uploadImg();" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="3" class="tac"><font class="red">如果您没有上传图片，系统将默认采用商品的主图片</font></td>
                        </tr>
                        </tbody>
                    </table>
                </form>
            </div>

            <!--{/if}-->

        </div>
    </div>


    <div class="bottom_fixbox">
        <div class="rectbox tac">
            <input type="button" class="btn" onclick="source.check();" value="添加资源位分类" />&nbsp;&nbsp;&nbsp;
            <input type="button" class="btn" onclick="E.closeWindows();" value="关闭" />
        </div>
    </div>

</div>

<script type="text/javascript">

    var source = {

        category_id: <!--{$category_id|default:0}-->,

        //检查数据
        check: function() {
            this.dt = E.getFormValues("source_form");
            var error_msg = "";
            if (this.dt.product_code == "")
                error_msg += "商品编码不能为空<br />";
            if (this.dt.hidden_product_code == "")
                error_msg += "未检查商品信息<br />";
            if (error_msg != "")
                E.alert(error_msg);
            else
                E.confirm("您确认要添加资源位信息吗？", "source.add");
        },

        //保存资源位信息
        add: function() {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/content/source.ajax?operFlg=3",
                dataType: "JSON",
                data: this.dt,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        if (source.category_id == 0)
                            E.opener("source.load");
                        E.alert(result_obj.message, 2, "E.closeWindows");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //上传图片
        uploadImg: function() {
            E.open("/quanliadmin/app/uploads/imageUpload.php?uploadPara=16", "上传", {height: 50, width: 600, top: 280, left: 300});
        },

        //清除商品信息
        clearGoods: function() {
            $("#product_code").val("").removeAttr("readonly", "readonly");
            $("#goods_name").text("");
            $("#goods_price").text("");
            $("#goods_img").html("");
            $("#hidden_product_code").html("");
            $("#clearBtn").hide();
        },

        //切换标签
        change: function(operFlg) {
            if (this.category_id) {
                self.location = "/quanliadmin/app/content/source.pscript?operFlg=" + operFlg + "&category_id=" + this.category_id;
            } else {
                self.location = "/quanliadmin/app/content/source.pscript?operFlg=" + operFlg;
            }
        }

    };

    // 页面完全载入后才初始化的jQuery函数.
    $(window).load(function() {

        //查询商品信息
        $("#product_code").keypress(function(event) {
            if (event.keyCode == 13) {
                event.preventDefault();
                var product_code = E.trim($("#product_code").val());
                if (product_code == "") {

                    E.alert("请输入商品编码");

                } else {

                    $.ajax({
                        type: "GET",
                        url: "/invokingAjax-backend/goods/goods.ajax?operFlg=1",
                        dataType: "JSON",
                        data: "product_code=" + product_code,
                        success: function( result_obj ) {
                            if (result_obj.code == 200) {
                                $("#goods_name").text(result_obj.data.goods_name);
                                $("#goods_price").text(result_obj.data.goods_price + " 元");
                                var list_html = "<img height=\"185px\" width=\"185px\" src=\"/quanliadmin/docroot/images/goods/" + result_obj.data.goodsMainPic + "\">";
                                $("#show_img").html(list_html);
                                $("#product_code").attr("readonly", "readonly");
                                $("#clearBtn").show();
                                $("#hidden_product_code").val(product_code);
                            } else {
                                E.alert(result_obj.message);
                            }
                        }
                    });

                }
            }
        });

    });


    function getUploadFileName(upload_fileName) {
        var list_html = "<img height=\"185px\" width=\"185px\" src=\"/quanliadmin/docroot/images/promotion/" + upload_fileName + "\">";
        $("#show_img").html(list_html);
        $("#promotion_img").val(upload_fileName);
    }


</script>

</body>

</html>
